﻿#include <winsock2.h>
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::string;
void Error(const string &msg)
{
  cout << msg << " error!" << endl;
  exit(-1);
}
void Print(const string &msg)
{
  cout << msg << endl;
}
int main(int args, char *argv[])
{
#ifndef SET_TERNIMAL_UTF8
  SetConsoleOutputCP(65001);
#endif
  WSADATA wsadata;
  WSAStartup(MAKEWORD(2, 2), &wsadata);
  sockaddr_in addr{};
  addr.sin_addr.S_un.S_addr = inet_addr(argv[1]);
  auto hostent = gethostbyaddr(argv[1], strlen(argv[1]), AF_INET);
  cout << std::boolalpha << (hostent == NULL) << endl;

  cout << argv[1] << "的官方域名为：" << hostent->h_name << endl;
  cout << argv[1] << "其它域名为：" << endl;
  for (int i = 0; hostent->h_aliases[i]; ++i)
    cout << hostent->h_aliases[i] << endl;
  cout << argv[1] << "IP的类型" << hostent->h_addrtype << endl;
  cout << argv[1] << "的其它IP地址：" << endl;
  for (int i = 0; hostent->h_addr_list[i]; ++i)
    cout << inet_ntoa(*(struct in_addr *)hostent->h_addr_list[i]) << endl;

  WSACleanup();
  return 0;
}